<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb' /></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" action="${web_domain}/securitys/users/" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label">用户名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="realName" placeholder="<fmt:message key='qrsxm' />" value="<c:if test='${params.realName !=null}'>${params.realName}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss' /></button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">
            <shiro:hasPermission name="users:create">
                <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="add"><i class="layui-icon">&#xe61f;</i> 添加</a>
            </shiro:hasPermission>

            <table class="layui-table" lay-size="sm">
                <thead>
                <th><fmt:message key='xh' /></th>
                <th><fmt:message key='zhanghao' /></th>
                <th><fmt:message key='js' /></th>
                <th><fmt:message key='xm' /></th>
                <th><fmt:message key='zt' /></th>
                <th><fmt:message key='cz' /></th>
                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td>${status.index + 1 }</td>
                        <td>${item.username }</td>
                        <td>${item.role.showName }</td>
                        <td>${item.realName }</td>
                        <td><b>${item.accountNonLocked ? "<fmt:message key='zc' />" : "<fmt:message key='sd' />" }</b></td>
                        <td>
                            <div class="layui-btn-container">

                                <shiro:hasPermission name="users:reset">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-reset"><fmt:message key='czmm' /></a>
                                </shiro:hasPermission>

                                <c:choose>
                                    <c:when test="${item.accountNonLocked}">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-locked"><fmt:message key='jy' /></a>
                                    </c:when>
                                    <c:otherwise>
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-unlocked"><fmt:message key='jj' /></a>
                                    </c:otherwise>
                                </c:choose>


                                <shiro:hasPermission name="users:modify">
                                    <a href="javascript:void(0);" data-url="${web_domain }/securitys/users/${item.id}/modify" class="layui-btn layui-btn-xs feijin-modify"><fmt:message key='bj' /></a>
                                </shiro:hasPermission>

                                <c:if test="${item.username != 'admin'}">
                                    <shiro:hasPermission name="users:remove">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-remove"><fmt:message key='sc' /></a>
                                    </shiro:hasPermission>
                                </c:if>
                            </div>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    $(function () {

        //添加用户
        $("#add").click(function () {
            layer.open({
                type: 2
                , title: '<fmt:message key='tjyh' />'
                , content: '${web_domain}/securitys/users/create'
                , maxmin: true
                , area: ['550px', '550px']
                , btn: ['<fmt:message key='qd' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //编辑
        $(".feijin-modify").click(function () {

            var url = $(this).attr("data-url");

            layer.open({
                type: 2
                , title: '<fmt:message key='tjyh' />'
                , content: url
                , maxmin: true
                , area: ['550px', '550px']
                , btn: ['<fmt:message key='qd' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //删除用户
        $(".feijin-remove").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='sczh' />',//自定义标题样式
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qrsczh' /></span>',
                    btn: ['<fmt:message key='sc' />', '<fmt:message key='qx' />'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/securitys/users/remove",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "delete"
                            },
                            success: function (data) {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });


        //重置密码
        $(".feijin-reset").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='czmm' />',//自定义标题样式
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qdczmm' /></span>',
                    btn: ['<fmt:message key='chongzhi' />', '<fmt:message key='qx' />'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/securitys/users/reset",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "put"
                            },
                            success: function (data) {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });

        //禁用
        $(".feijin-locked").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='jyzh' />',//自定义标题样式
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qrjyzh' /></span>',
                    btn: ['<fmt:message key='jy' />', '<fmt:message key='qx' />'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/securitys/users/lock",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "put"
                            },
                            success: function (data) {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });

        //解除禁用
        $(".feijin-unlocked").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='jj' />',//自定义标题样式
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qrhfzh' /></span>',
                    btn: ['<fmt:message key='jj' />', '<fmt:message key='qx' />'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/securitys/users/unlock",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "put"
                            },
                            success: function (data) {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });
    });
</script>
</body>
</fmt:bundle>
</html>
